/**
 * 时间本地化修复测试文件
 * 用于验证统一时间工具的正确性
 */

import { 
  formatLocalDate,
  formatShortDate,
  formatLocalDateTime,
  formatRelativeTime,
  getDateStatus,
  getDateStatusText,
  getDateStatusStyle,
  getTimeContext,
  getTodayString,
  getTomorrowString
} from './timeUtils'

// 测试用例
export function runTimeTests() {
  console.log('🧪 开始时间本地化测试...')
  
  // 测试数据
  const today = new Date()
  const tomorrow = new Date(today)
  tomorrow.setDate(today.getDate() + 1)
  
  const yesterday = new Date(today)
  yesterday.setDate(today.getDate() - 1)
  
  const nextWeek = new Date(today)
  nextWeek.setDate(today.getDate() + 7)
  
  // 测试场景：今天创建，明天8点到期的任务
  const tomorrowMorning = new Date(tomorrow)
  tomorrowMorning.setHours(8, 0, 0, 0)
  
  console.log('📅 测试场景1: 今天创建，明天8点到期')
  console.log('- 截止时间:', tomorrowMorning.toISOString())
  console.log('- 状态判断:', getDateStatus(tomorrowMorning))
  console.log('- 状态文本:', getDateStatusText(tomorrowMorning))
  console.log('- 样式类名:', getDateStatusStyle(tomorrowMorning, false))
  
  console.log('\n📅 测试场景2: 各种时间格式化')
  console.log('- 本地日期:', formatLocalDate(today))
  console.log('- 简短日期:', formatShortDate(today))
  console.log('- 本地日期时间:', formatLocalDateTime(today))
  console.log('- 相对时间:', formatRelativeTime(yesterday))
  
  console.log('\n📅 测试场景3: 时间上下文分析')
  const timeContext = getTimeContext(today, tomorrowMorning)
  console.log('- 时间跨度:', timeContext.timeSpan)
  console.log('- 紧急程度:', timeContext.urgency)
  console.log('- 上下文:', timeContext.context)
  
  console.log('\n📅 测试场景4: 快速日期生成')
  console.log('- 今天字符串:', getTodayString())
  console.log('- 明天字符串:', getTomorrowString())
  
  console.log('\n✅ 时间本地化测试完成！')
  
  return {
    todayStatus: getDateStatus(today),
    tomorrowStatus: getDateStatus(tomorrowMorning),
    yesterdayStatus: getDateStatus(yesterday),
    timeContext
  }
}

// 验证修复效果的函数
export function verifyTimeFix() {
  console.log('🔍 验证时间判断逻辑修复...')
  
  // 创建测试用例：今天创建，明天早上8点到期
  const today = new Date()
  const tomorrowMorning = new Date(today)
  tomorrowMorning.setDate(today.getDate() + 1)
  tomorrowMorning.setHours(8, 0, 0, 0)
  
  const todayEvening = new Date(today)
  todayEvening.setHours(23, 59, 0, 0)
  
  console.log('测试用例1: 明天早上8点到期')
  console.log('- 应该显示: "明天到期"')
  console.log('- 实际显示:', getDateStatusText(tomorrowMorning))
  console.log('- 状态正确:', getDateStatus(tomorrowMorning) === 'tomorrow' ? '✅' : '❌')
  
  console.log('\n测试用例2: 今天晚上11:59到期')
  console.log('- 应该显示: "今天到期"')
  console.log('- 实际显示:', getDateStatusText(todayEvening))
  console.log('- 状态正确:', getDateStatus(todayEvening) === 'today' ? '✅' : '❌')
  
  console.log('\n🎉 Bug修复验证完成！')
  
  return {
    tomorrowMorningFixed: getDateStatus(tomorrowMorning) === 'tomorrow',
    todayEveningCorrect: getDateStatus(todayEvening) === 'today'
  }
}